<template>
  <div style="text-align: center; width: 680px; margin: auto; background: #fff">
    <table
      cellpadding="0"
      cellspacing="0"
      style="
        table-layout: fixed;
        position: relative;
        width: 95%;
        font-family: 仿宋_GB2312;
        font-size: 16px;
        margin: auto;
      "
    >
      <tr style="height: 10px">
        <td
          v-for="item in 100"
          :key="item"
          style="width: 1%; text-align: center"
        />
      </tr>
      <tr style="height: 60px">
        <td colspan="100" style="text-align: center">
          <span id="Lab_title" style="font-size: 24px; font-weight: bold"
            >注册二级造价工程师（水利工程）延续注册申请表</span
          >
        </td>
      </tr>
      <tr style="height: 50px">
        <td colspan="23" class="TableBorderOther">是否为川渝通办件</td>
        <td colspan="30" class="TableBorderRight">
          <el-checkbox
              v-model="formData.serviceType"
              class="input-center"
              :disabled="disabled"
              true-label="3"
              false-label="1"
              :checked="formData.serviceType==='3'"
          />
        </td>
      </tr>
      <tr style="height: 50px">
        <td colspan="14" class="TableBorderOther">姓名</td>
        <td colspan="14" class="TableBorderOther">
          {{ tempFormData.name }}
        </td>
        <td colspan="14" class="TableBorderOther">性别</td>
        <td colspan="14" class="TableBorderOther">
          <Aselect
            :disabled="disabled || checkValue1 === '111'"
            v-model="tempFormData.sex"
            :options="$dict('sex').list()"
            placeholder=""
          />
        </td>
        <td colspan="14" class="TableBorderOther">出生年月</td>
        <td colspan="14" class="TableBorderOther">
          <AdatePicker
            :disabled="disabled || checkValue1 === '111'"
            v-model="tempFormData.birthday"
            :clearable="false"
            placeholder=""
          />
        </td>
        <td colspan="16" rowspan="3" class="TableBorderRight">
          <img
            style="width: 100%; height: 100%"
            :src="tempFormData.idPhoto && tempFormData.idPhoto.thumbnailUri"
            alt=""
          />
        </td>
      </tr>
      <tr style="height: 50px">
        <td colspan="14" class="TableBorderOther">证件名称</td>
        <td colspan="70" class="TableBorderOther">
          <span
            ><input
              :checked="checkValue1 === '111'"
              @click="idCardChecked()"
              type="checkbox"
              style="margin-right: 10px"
              :disabled="true"
            />身份证</span
          >
          <span style="margin-left: 16px"
            ><input
              :checked="checkValue1 === '114'"
              @click="checkValue1 = '114'"
              type="checkbox"
              style="margin-right: 10px"
              :disabled="true"
            />军官证</span
          >
          <span style="margin-left: 16px"
            ><input
              :checked="checkValue1 === '099'"
              @click="checkValue1 = '099'"
              type="checkbox"
              style="margin-right: 10px"
              :disabled="true"
            />其他</span
          >
        </td>
      </tr>
      <tr style="height: 50px">
        <td colspan="14" class="TableBorderOther">证件号码</td>
        <td colspan="70" class="TableBorderOther">
          <input
            :disabled="true"
            v-model="tempFormData.paperCode"
            type="text"
            class="input-center"
          />
        </td>
      </tr>
      <tr style="height: 60px">
        <td colspan="25" class="TableBorderOther">资格证书编号</td>
        <td colspan="25" class="TableBorderOther">
          {{ tempFormData.paperCertCode }}
        </td>
        <td colspan="25" class="TableBorderOther">
          原注册有效期内继续<br />教育学时数
        </td>
        <td colspan="25" class="TableBorderRight">
          <input
            :disabled="disabled"
            v-model.number="tempFormData.eduHours"
            type="number"
            class="input-center"
          />
        </td>
      </tr>
      <tr style="height: 60px">
        <td colspan="25" class="TableBorderOther">注册证书编号</td>
        <td colspan="25" class="TableBorderOther">
          <input
            :disabled="disabled"
            v-model.trim="tempFormData.certCode"
            type="text"
            class="input-center"
            readonly
          />
        </td>
        <td colspan="25" class="TableBorderOther">注册有效期<br />届满时间</td>
        <td colspan="25" class="TableBorderRight">
          <AdatePicker
            :disabled="true"
            v-model="tempFormData.certEndTime"
            :clearable="false"
            placeholder=""
          />
        </td>
      </tr>
      <tr style="height: 50px">
        <td colspan="10" rowspan="4" class="TableBorderOther">
          聘用<br />单位
        </td>
        <td colspan="15" class="TableBorderOther">单位名称</td>
        <td colspan="75" class="TableBorderRight">
          <input
            :disabled="disabled"
            v-model.trim="tempFormData.employUnit"
            type="text"
            class="input-center"
            readonly
          />
        </td>
      </tr>
      <tr style="height: 50px">
        <td colspan="15" class="TableBorderOther">统一社会<br />信用代码</td>
        <td colspan="75" class="TableBorderRight">
          <input
            :disabled="disabled"
            v-model.trim="tempFormData.creditCode"
            type="text"
            class="input-center"
            readonly
          />
        </td>
      </tr>
      <tr style="height: 50px">
        <td colspan="15" class="TableBorderOther">通信地址</td>
        <td colspan="75" class="TableBorderRight">
          <input
            :disabled="disabled"
            v-model.trim="tempFormData.employAddress"
            type="text"
            class="input-center"
            readonly
          />
        </td>
      </tr>
      <tr style="height: 50px">
        <td colspan="15" class="TableBorderOther">工商登记地</td>
        <td colspan="30" class="TableBorderOther">
          <ProSelect
            v-model="tempFormData.employRegistPlace"
            placeholder=""
            :disabled="true"
          />
        </td>
        <td colspan="15" class="TableBorderOther">经办人手机<br />号码</td>
        <td colspan="30" class="TableBorderRight">
          <input
            :disabled="disabled"
            v-model.trim="tempFormData.jbrTel"
            type="text"
            class="input-center"
            readonly
          />
        </td>
      </tr>
      <tr style="height: 50px">
        <td colspan="25" class="TableBorderBottom">申请人手机号码</td>
        <td colspan="30" class="TableBorderBottom">
          <input
            :disabled="disabled"
            v-model.trim="tempFormData.sqrTel"
            type="text"
            class="input-center"
            readonly
          />
        </td>
        <td colspan="15" class="TableBorderBottom">注册地</td>
        <td colspan="30" class="TableBorderRightBottom">
          <ProSelect
              v-model="tempFormData.registPlace"
              placeholder=""
              :disabled="true"
          />
        </td>
      </tr>
    </table>
  </div>
</template>
<script>
import AdatePicker from '@/components/TimePicker/AdatePicker';
import Aselect from '@/components/Select/Aselect';
import ProSelect from '@/components/AreaSelect/ProSelect';
import { fieldsValidate } from '@/utils/validate.js';
export default {
  props: {
    formData: {
      type: Object,
    },
    disabled: {
      type: Boolean,
      default: false,
    },
  },
  components: { AdatePicker, Aselect, ProSelect },
  data() {
    return {
      checkValue1: '111',
      idCode: '',
      tempFormData: {},
    };
  },
  watch: {
    formData: {
      handler(val) {
        this.tempFormData = val || {};
        if (this.tempFormData.paperType === '111') {
          this.idCode = this.tempFormData.paperCode;
        }
      },
      immediate: true,
    },
    checkValue1: {
      handler(val) {
        this.tempFormData.paperType = val;
      },
      immediate: true,
    },
  },
  methods: {
    // 证件类型
    idCardChecked() {
      this.checkValue1 = this.checkValue1 === '111' ? undefined : '111';
      this.tempFormData = {
        ...this.tempFormData,
        paperCode: this.idCode,
      };
    },
    // 校验规则
    validateFields() {
      const rules = {
        eduHours: [
          { required: true, text: '请输入原注册有效期内继续教育学时数' },
          {
            maxLength: 5,
            text: '学时数不应超过5位',
          },
          { pattern: /^[1-9]\d*$/, text: '学时数应为正整数' },
        ],
      };
      return fieldsValidate(this.tempFormData, rules, this);
    },
    // 校验表单
    validateForm() {
      const reg = /^1[3456789]\d{9}$/;
      if (
        !this.tempFormData.sqrTel ||
        !reg.test(this.tempFormData.sqrTel) ||
        !this.tempFormData.jbrTel ||
        !reg.test(this.tempFormData.jbrTel)
      ) {
        this.$message.error('请输入正确的手机号码');
        return false;
      }
      const idReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
      const officerReg = /^[\u4E00-\u9FA5](字第)([0-9a-zA-Z]{4,8})(号?)$/;
      if (
        this.tempFormData.paperType === '111' &&
        !idReg.test(this.tempFormData.paperCode)
      ) {
        this.$message.error('请输入正确的身份证号码');
        return false;
      } else if (
        this.tempFormData.paperType === '114' &&
        !officerReg.test(this.tempFormData.paperCode)
      ) {
        this.$message.error('请输入正确的军官证号码');
        return false;
      }
      return this.validateFields();
    },
  },
};
</script>
<style lang="scss" scoped>
@import '../../../../../../assets/styles/word.scss';
</style>
